/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Ingresar_asesor.java
 *
 * Created on Jul 21, 2011, 12:17:31 PM
 */
package Asesor;
import callProcs.ProcsAsesores;
import callProcs.ProcsInsertar;

import javax.swing.JOptionPane;

/**
 *
 * @author Juls
 */
public class Ingresar_asesor extends javax.swing.JFrame {
 
    /** Creates new form Ingresar_asesor */
    public Ingresar_asesor() {
        initComponents();
        
        if(BuscarEditar_asesor.datosasesor.size()!=0 ){
      
        
        Nombres_Asesor.setText(BuscarEditar_asesor.datosasesor.get(1));
        Apellidos_Asesor.setText(BuscarEditar_asesor.datosasesor.get(2));
        Telefono_asesor.setText(BuscarEditar_asesor.datosasesor.get(3));
        Email_asesor.setText(BuscarEditar_asesor.datosasesor.get(4));
                   jLabel5.setText("Editar Asesor");
        Ingresar_asesor.this.setTitle("Editar Asesor");
            
        
        if (BuscarEditar_asesor.datosasesor.get(5).equals("true"))
            {
                 Activocheck_ByE.setSelected(true);
            
            }
            else
            {
               Inactivocheck_ByE.setSelected(true); 
            
            } 
            
            //aki voy a ingresar el codigo para editar el asesor seleccionado

        
        }
        else{  //codigo de ingreso de nuevo asesor
  
        jLabel7.setVisible(false);
        Activocheck_ByE.setVisible(false);
        Inactivocheck_ByE.setVisible(false);

        }
        
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Acept_IngAs = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        Nombres_Asesor = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        Apellidos_Asesor = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        Telefono_asesor = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        Email_asesor = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        Activocheck_ByE = new javax.swing.JRadioButton();
        Inactivocheck_ByE = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(bufete.BufeteApp.class).getContext().getResourceMap(Ingresar_asesor.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);

        Acept_IngAs.setIcon(resourceMap.getIcon("Acept_IngAs.icon")); // NOI18N
        Acept_IngAs.setText(resourceMap.getString("Acept_IngAs.text")); // NOI18N
        Acept_IngAs.setToolTipText(resourceMap.getString("Acept_IngAs.toolTipText")); // NOI18N
        Acept_IngAs.setActionCommand(resourceMap.getString("Acept_IngAs.actionCommand")); // NOI18N
        Acept_IngAs.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        Acept_IngAs.setName("Acept_IngAs"); // NOI18N
        Acept_IngAs.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Acept_IngAsMouseClicked(evt);
            }
        });
        Acept_IngAs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Acept_IngAsActionPerformed(evt);
            }
        });

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setIcon(resourceMap.getIcon("jLabel6.icon")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        Nombres_Asesor.setText(resourceMap.getString("Nombres_Asesor.text")); // NOI18N
        Nombres_Asesor.setName("Nombres_Asesor"); // NOI18N
        Nombres_Asesor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                Nombres_AsesorKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                Nombres_AsesorKeyPressed(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        Apellidos_Asesor.setText(resourceMap.getString("Apellidos_Asesor.text")); // NOI18N
        Apellidos_Asesor.setName("Apellidos_Asesor"); // NOI18N
        Apellidos_Asesor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                Apellidos_AsesorKeyTyped(evt);
            }
        });

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        Telefono_asesor.setText(resourceMap.getString("Telefono_asesor.text")); // NOI18N
        Telefono_asesor.setName("Telefono_asesor"); // NOI18N
        Telefono_asesor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                Telefono_asesorKeyTyped(evt);
            }
        });

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        Email_asesor.setText(resourceMap.getString("Email_asesor.text")); // NOI18N
        Email_asesor.setName("Email_asesor"); // NOI18N

        jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        Activocheck_ByE.setText(resourceMap.getString("Activocheck_ByE.text")); // NOI18N
        Activocheck_ByE.setName("Activocheck_ByE"); // NOI18N
        Activocheck_ByE.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Activocheck_ByEMouseClicked(evt);
            }
        });

        Inactivocheck_ByE.setText(resourceMap.getString("Inactivocheck_ByE.text")); // NOI18N
        Inactivocheck_ByE.setName("Inactivocheck_ByE"); // NOI18N
        Inactivocheck_ByE.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Inactivocheck_ByEMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(60, 60, 60)
                        .addComponent(Activocheck_ByE)
                        .addGap(51, 51, 51)
                        .addComponent(Inactivocheck_ByE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Apellidos_Asesor, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Nombres_Asesor, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Telefono_asesor, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(Email_asesor, javax.swing.GroupLayout.DEFAULT_SIZE, 489, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(68, 68, 68)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(Nombres_Asesor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(Apellidos_Asesor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(Telefono_asesor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(Email_asesor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(Activocheck_ByE)
                    .addComponent(Inactivocheck_ByE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 364, Short.MAX_VALUE)
                        .addComponent(Acept_IngAs, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(217, 217, 217)
                        .addComponent(jLabel5)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Acept_IngAs, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Acept_IngAsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Acept_IngAsMouseClicked
        // TODO add your handling code here:
 
        if(BuscarEditar_asesor.datosasesor.size()!=0 ){
            
             if ((Nombres_Asesor.getText().equals(""))|| (Apellidos_Asesor.getText().equals(""))||(Telefono_asesor.getText().equals(""))||(Email_asesor.getText().equals(""))||(Activocheck_ByE.isSelected()==false)&&(Inactivocheck_ByE.isSelected()==false))
          {
              JOptionPane.showMessageDialog(null, "Debe ingresar todos los campos", "Campo Obligatorio", JOptionPane.WARNING_MESSAGE);   
          
          } 
         else
         { 
          ProcsAsesores ActAs = new ProcsAsesores();
            if (Activocheck_ByE.isSelected()==true)
             {
                 ActAs.ActualizarAsesor(BuscarEditar_asesor.datosasesor.get(0), Nombres_Asesor.getText(),Apellidos_Asesor.getText(),Telefono_asesor.getText(),Email_asesor.getText(),"True");
             }
            if (Inactivocheck_ByE.isSelected()==true)
             {
                 ActAs.ActualizarAsesor(BuscarEditar_asesor.datosasesor.get(0), Nombres_Asesor.getText(),Apellidos_Asesor.getText(),Telefono_asesor.getText(),Email_asesor.getText(),"False");
             }
           
            if(JOptionPane.showConfirmDialog(null, "Asesor Ingresado Exitosamente. ¿Desea Editar un Nuevo Asesor?" , "Edición Correcto", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
             {
                
      
             
             
             
             }
            else
            {
               this.dispose();
            }             
            
            //aki voy a ingresar el codigo para editar el asesor seleccionado
        System.out.println("mierda");
         }
        
        }
        
        else{  //sino va aingresar uno nuevo 

        if ((Nombres_Asesor.getText().equals(""))|| (Apellidos_Asesor.getText().equals(""))||(Telefono_asesor.getText().equals(""))||(Email_asesor.getText().equals("")))
        {
 
             JOptionPane.showMessageDialog(null, "Debe ingresar todos los campos", "Campo Obligatorio", JOptionPane.WARNING_MESSAGE);                       
        } 
        else
        {
             ProcsInsertar InAsesor = new ProcsInsertar();
        String nomAsesor = Nombres_Asesor.getText();
        String apeAsesor = Apellidos_Asesor.getText();
        String TelAsesor = Telefono_asesor.getText();
        String emailAsesor = Email_asesor.getText();
        boolean bandera = false;
         InAsesor.insertarAsesor(nomAsesor, apeAsesor,TelAsesor,emailAsesor,bandera);
  
          if(JOptionPane.showConfirmDialog(null, "Asesor Ingresado Exitosamente. ¿Desea Ingresar un Nuevo Asesor?" , "Ingreso Correcto", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_NO_OPTION)   
          {
              
              
              Nombres_Asesor.setText("");
              Apellidos_Asesor.setText("");
              Telefono_asesor.setText("");
              Email_asesor.setText("");
              
              
          }
          else
          {
              this.dispose();
          }
    }//GEN-LAST:event_Acept_IngAsMouseClicked
}
    }
    private void Nombres_AsesorKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Nombres_AsesorKeyPressed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_Nombres_AsesorKeyPressed

    private void Nombres_AsesorKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Nombres_AsesorKeyTyped
        // TODO add your handling code here:
         char caracter = evt.getKeyChar();
         if(((Character.isDigit(caracter)== true && caracter!= evt.VK_BACK_SPACE)))
      {
         evt.consume();  // ignorar el evento de teclado
      }  
    }//GEN-LAST:event_Nombres_AsesorKeyTyped

    private void Apellidos_AsesorKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Apellidos_AsesorKeyTyped
        // TODO add your handling code here:
         char caracter = evt.getKeyChar();
         if(((Character.isDigit(caracter)== true && caracter!= evt.VK_BACK_SPACE)))
      {
         evt.consume();  // ignorar el evento de teclado
      }  
    }//GEN-LAST:event_Apellidos_AsesorKeyTyped

    private void Telefono_asesorKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Telefono_asesorKeyTyped
        // TODO add your handling code here:
         char caracter = evt.getKeyChar();
         if(((Character.isDigit(caracter)== false && caracter!= evt.VK_BACK_SPACE))|| Telefono_asesor.getText().length() >= 8)
      {
         evt.consume();  // ignorar el evento de teclado
      }  
    }//GEN-LAST:event_Telefono_asesorKeyTyped

    private void Acept_IngAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Acept_IngAsActionPerformed
        // TODO add your handling code here:

        /*
        ProcsInsertar InAsesor = new ProcsInsertar();
        String nomAsesor = Nombres_Asesor.getText();
        String apeAsesor = Apellidos_Asesor.getText();
        String TelAsesor = Telefono_asesor.getText();
        String emailAsesor = Email_asesor.getText();
        boolean bandera = false;
         InAsesor.insertarAsesor(nomAsesor, apeAsesor,TelAsesor,emailAsesor,bandera);*/
    }//GEN-LAST:event_Acept_IngAsActionPerformed

    private void Activocheck_ByEMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Activocheck_ByEMouseClicked
        // TODO add your handling code here:
        if(Activocheck_ByE.isSelected()==true) {
            Inactivocheck_ByE.setSelected(false);
        }
        
    }//GEN-LAST:event_Activocheck_ByEMouseClicked

    private void Inactivocheck_ByEMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Inactivocheck_ByEMouseClicked
        // TODO add your handling code here:
        if(Inactivocheck_ByE.isSelected()==true) {
            Activocheck_ByE.setSelected(false);
        }
}//GEN-LAST:event_Inactivocheck_ByEMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Ingresar_asesor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Acept_IngAs;
    private javax.swing.JRadioButton Activocheck_ByE;
    private javax.swing.JTextField Apellidos_Asesor;
    private javax.swing.JTextField Email_asesor;
    private javax.swing.JRadioButton Inactivocheck_ByE;
    private javax.swing.JTextField Nombres_Asesor;
    private javax.swing.JTextField Telefono_asesor;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
